package proyecto.testcasetool.provider.main;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.edit.provider.IDisposable;

import proyecto.testcasetool.UseCaseModel;
import proyecto.testcasetool.provider.UseCaseModelItemProvider;

public class UseCaseModelItemProviderMain extends UseCaseModelItemProvider {

	public UseCaseModelItemProviderMain(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	protected List children = null;
	protected ActorsGhostItemProvider actorsItemProvider;
	
	@Override
	public Collection<?> getChildren(Object object) {
		UseCaseModel model = (UseCaseModel) object;
		if (children == null) {
			children = new ArrayList();
			// El modelo se carga con el subject ya creado.

			children.add(model.getSubject());
			this.actorsItemProvider = new ActorsGhostItemProvider(adapterFactory, model);
			children.add(this.actorsItemProvider);

		}
		else{
			if (model.getSubject() == null){
				children = new ArrayList();
				children.add(this.actorsItemProvider);
			}
			else if(model.getSubject() != null && children.size()==1){
				children = new ArrayList();
				children.add(model.getSubject());
				children.add(this.actorsItemProvider);
			}
		}
		return children;
	}

	public Object getActors() {
		return this.actorsItemProvider;
	}

	@Override
	protected void collectNewChildDescriptors(
			Collection<Object> newChildDescriptors, Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);
	}

	/**
	 * Disposes the non-modeled children.
	 */
	@Override
	public void dispose() {
		super.dispose();
		if (children != null) {
			((IDisposable) children.get(1)).dispose();
		}
	}

	
}
